package com.sojoys.artifact.plugin.netty.coder;

import com.sojoys.artifact.factory.message.IMessage;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

public class NettyMessageEncoder extends MessageToByteEncoder<IMessage>{

	@Override
	protected void encode(ChannelHandlerContext arg0, IMessage msg, ByteBuf out) throws Exception {
		out.writeIntLE(msg.getBody().length + 10 - 4);
		out.writeShortLE(msg.getCommandId());
		out.writeIntLE(msg.getStatus());
		out.writeBytes(msg.getBody());
	}
}
